#coding=utf-8
'''
Created on 2017-04-20

@author: sandy
'''

import json
from pycommon import Pack as packet
from pycommon import Const
from pycommon import Utils

def clientLogin(code):
    return packet.pack("HH", Const.CMD_GAME2C_LOGIN,code)
    pass

def joinTable(code,tableInfo):
    return packet.pack("HHs",Const.CMD_GAME2C_JOIN,code,Utils.u2pstr(tableInfo))


def tableUserInfo(seatnum,users):
    c = len(users)
    ret = packet.pack("HHH",Const.CMD_GAME2C_SELF_ENTER,seatnum,c)
    for u in users:
        prop = u.getProp()
        property = u.getProperty()
        ret += packet.pack("IHssBSS",
                            u.getUid(),
                            u.getSeatNum(),
                            Utils.u2pstr(u.getPhoto()),
                            Utils.u2pstr(u.getNickname()),
                            u.getSex(),
                            json.dumps(prop),
                            json.dumps(property)
                        )
    return ret

def tableUserEnter(uid,seatnum,photo,nickname,sex,prop,property):
    return packet.pack("HIHssBSS",Const.CMD_GAME2C_OTHER_ENTER,uid,seatnum,Utils.u2pstr(photo),Utils.u2pstr(nickname),sex,json.dumps(prop),json.dumps(property))

def tableUserLeave(uid,seatnum,reason):
    return packet.pack("HIHB",Const.CMD_GAME2C_USER_LEAVE,uid,seatnum,reason)

def kickUser():
    return packet.pack("H",Const.CMD_GAME2C_KICK)
    







